<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>MODEL</title>
    <link rel="stylesheet" href=""/>
    <script src="js/jquery.js"></script>
    <script src="js/underscore.js"></script>
    <script src="js/backbone.js"></script>
</head>
<body>
<script>
    $(function () {
        var Man = Backbone.Model.extend({
            initialize: function () {
                console.log('Hey, you create me!');
                //初始化时绑定监听
                this.bind("change:name", function () {
                    var name = this.get("name");
                    console.log("你改变了name属性为：" + name);
                });
                this.bind("invalid", function (model, error) {
                    console.log(error);
                });
            },
            defaults: {
                name: '张三',
                age: '38'
            },
            validate: function (attributes) {
                if (attributes.name == '') {
                    return "name不能为空！";
                }
            },
            aboutMe: function () {
                return '我叫' + this.get('name') + ',今年' + this.get('age') + '岁';
            }
        });
        var man = new Man;
        man.set({name: ''}, {validate: true});
    });
</script>
</body>
</html>